const express = require('express');

const mongoose = require('mongoose');
const bodyPaser = require('body-parser')
const User = require('./routes/Users')
const {SuccessModel, ErroModel} = require('./models/common')

let options = {
    useNewUrlParser: true,
    useFindAndModify: false,
    useCreateIndex: true,
}

const MONGO_URL = 'mongodb://book:ABABcdcd1212@106.12.140.35/book';

mongoose.connect(MONGO_URL, options);

mongoose.connection.on('open', () => {
    console.log('MongoDB Connected!')
})

const app = express();
app.use(bodyPaser.urlencoded({extended:true}))
app.use(bodyPaser.json())
app.use('/api/v1/user', User)

app.get('/',(req, res) => {
    res.json(new SuccessModel("欢迎"))
})

app.get('/u')

app.use((req, res)=> {
    res.json(new ErroModel("您访问的页面出错了！"))
})


app.listen(3000, () => {
    console.log('server up on 3000!')
})